/* BusinessLayerService 2010/11/13 19:26:25
*/
        #region REGWFTableList
      /* 2010/11/13 19:26:25*/ 
         case "WFEditTableList":
         workflowType = typeof(WFEditTableList);
          break;
        #endregion
        #region DataBaseLayerService
    case "TableList":
         TableList m_TableList = new TableList(cmdSQL, dtRequest, RequestJob);
           cmdSQL = m_TableList.BuildCommand();
            break;
        #endregion
        
		#region ServerERPBLService.cs/TableList
	                case "OnQueryTableList":
                        /* 
                        ServerERPBLService 2010/11/13 19:26:25
                         */
                    m_TableListManagement = new TableListManagement(DicGlobalPara);
                    MsgReturn.dsReturn = m_TableListManagement.QueryTableList(null);
                    break;
				#endregion
                
        #region LanSunAgent.cs /TableList
             /* 
        LanSunAgent 2010/11/13 19:26:25
        */
        #region TableList
                    case "OnListTableList":
                        mnu_ListTableList_Click(thisNode);
                        break;
                    case "OnQueryTableList":
                        mnu_QueryTableList_Click(thisNode);
                        break;
                    case "OnEditTableList":
                        mnu_EditTableList_Click(thisNode);
                        break;
                    #endregion
                    
        #region TableList
    
        private void mnu_ListTableList_Click(ExMenuNode thisNode)
        {
            try
            {
                if (thisNode.EventMessageEx == null)
                {
                    thisNode.EventMessageEx = RequestMessage;
                }
                MessageEx WFMsgRequest = new MessageEx(thisNode.EventMessageEx);
                WFMsgRequest.JobType = "UI2WF";
                WFMsgRequest.JobID = "OnListTableList";
                WFMsgRequest.JobContent = "WFEditTableList";
                WFMsgRequest.dsRequest = null;
                WFMsgRequest.dsReturn = new DataSet();
                WFMsgRequest.dsReturn = thisNode.DataSetEvent;
                WFMsgRequest.MessageID_Req = WFMsgRequest.MessageID;
                WFMsgRequest.MessageID_Return = WFMsgRequest.MessageID;
                ((BaseDockForm)thisNode.OwnerForm).SendWFMessage(WFMsgRequest);
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }
        }
        private void mnu_QueryTableList_Click(ExMenuNode thisNode)
        {
            try
            {
                dicBaseInitPara["RequestMessage"] = thisNode.EventMessageEx;
                dicBaseInitPara["ExChangeDataSet"] = thisNode.DataSetEvent;
                TableListQueryCond m_QueryCond = new TableListQueryCond();
                this.ChildWindowList.Add(m_QueryCond.m_AgentCallbackPath, m_QueryCond);
                m_QueryCond.dicBaseInitPara = this.dicBaseInitPara;
                m_QueryCond.dicBaseInitPara["This_Agent"] = this.This_Agent;
                m_QueryCond.dicBaseInitPara["BaseTable"] = "Default";
                m_QueryCond.dicBaseInitPara["CurrentPosition"] = 0;
                m_QueryCond.dicBaseInitPara["StartQuery"] = false;
                m_QueryCond.dicBaseInitPara["m_Base"] = m_QueryCond.m_Base;
                m_QueryCond.Show(this.MainDockPanel);
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }
        }
        private void mnu_EditTableList_Click(ExMenuNode thisNode)
        {
            dicBaseInitPara["RequestMessage"] = thisNode.EventMessageEx;
            dicBaseInitPara["ExChangeDataSet"] = thisNode.DataSetEvent;
            TableList m_QueryCond = new TableList();
            this.ChildWindowList.Add(m_QueryCond.m_AgentCallbackPath, m_QueryCond);
            string BaseTable = m_QueryCond.m_Base.BaseTable;
            try
            {
                m_QueryCond.dicBaseInitPara = this.dicBaseInitPara;
                m_QueryCond.dicBaseInitPara["This_Agent"] = this.This_Agent;
                m_QueryCond.dicBaseInitPara["BaseTable"] = "Default";
                m_QueryCond.dicBaseInitPara["CurrentPosition"] = 0;
                m_QueryCond.dicBaseInitPara["StartQuery"] = false;
                m_QueryCond.dicBaseInitPara["m_Base"] = m_QueryCond.m_Base;
                m_QueryCond.Show(this.MainDockPanel);
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }
        }
        #endregion
        #endregion
        
        #region MenuBuild TableList
 
 select * from MenuBuild where MenuKey like '%TableList%'
 --delete from MenuBuild where MenuKey like '%TableList%'
          DECLARE	@TableID varchar(6)
          select @TableID=TableID from TableList where TableName='TableList'
         INSERT INTO "MenuBuild"("SysID", "InstanceID", "InstanceKey", "MenuID", "MenuKey", "UpperMenuID", "UpperMenuKey", "LongDes", "ShortDes", "EventKey", "UserID", "Text_EN", "Text_CN", "FrstUser", "FrstDate", "LastUser", "LastDate", "SubStatus", "Status")
VALUES ('1         ', null, null, @TableID, 'mnu_TableList', '2200', null, null, null, 'TableList', null, 'GoodsMaster', 'TableList_Management', null, null, null, null, 'Complete', 'Complete')
 
INSERT INTO "MenuBuild"("SysID", "InstanceID", "InstanceKey", "MenuID", "MenuKey", "UpperMenuID", "UpperMenuKey", "LongDes", "ShortDes", "EventKey", "UserID", "Text_EN", "Text_CN", "FrstUser", "FrstDate", "LastUser", "LastDate", "SubStatus", "Status")
VALUES ('1         ', null, null, @TableID+'1', 'mnu_ListTableList', @TableID, null, null, null, 'OnListTableList', null, 'ListTableList', 'ListTableList', null, null, null, null, 'Complete', 'Complete')
  
INSERT INTO "MenuBuild"("SysID", "InstanceID", "InstanceKey", "MenuID", "MenuKey", "UpperMenuID", "UpperMenuKey", "LongDes", "ShortDes", "EventKey", "UserID", "Text_EN", "Text_CN", "FrstUser", "FrstDate", "LastUser", "LastDate", "SubStatus", "Status")
VALUES ('1         ', null, null, @TableID+'2', 'mnu_QueryTableList', @TableID, null, null, null, 'OnQueryTableList', null, 'QueryTableList', 'QueryTableList', null, null, null, null, 'Complete', 'Complete')
INSERT INTO "MenuBuild"("SysID", "InstanceID", "InstanceKey", "MenuID", "MenuKey", "UpperMenuID", "UpperMenuKey", "LongDes", "ShortDes", "EventKey", "UserID", "Text_EN", "Text_CN", "FrstUser", "FrstDate", "LastUser", "LastDate", "SubStatus", "Status")
VALUES ('1         ', null, null, @TableID+'3', 'mnu_EditTableList', @TableID, null, null, null, 'OnEditTableList', null, 'EditTableList', 'EditTableList', null, null, null, null, 'Complete', 'Complete')
GO
 INSERT INTO "TableList2Agent"("InstanceID", "InstanceKey", "SysID", "TableID", "TableName", "AgentID", "AgentName", "Task", "TContent", "ShortName", "SubStatus", "KeyCondition", "Status", "FrstUser", "FrstDate", "LastUser", "LastDate")
VALUES ('9100080LANSUN', '9MenuBuilLANSUN', '1', '100080', 'MenuBuild', 'LANSUN', 'LANSUN', 'DataChange', '', '  ', 'UPDATE', 'UPDATE', 'UPDATE', null, null, null, null)
GO
#endregion             
        
        #region BLTableList 
        #region QueryCond
        public DataSet QueryTableList(DataRow dwQueryCond)
        {
            DataSet DsReturn = new DataSet();
            try
            {
                if (dwQueryCond == null)
                {
                    dwQueryCond = dwRequest;
                }

                string QueryType = dwQueryCond["QueryType"].ToString().Trim();
                string ConditionType = dwQueryCond["ConditionType"].ToString().Trim();
                string BaseTable = "TableList";
                string DBJobID = "1002";
                DataRow dwTableList = dsParameters.Tables[BaseTable].Clone().Rows.Add();
                dwTableList =MapDataRow("", "", BaseTable, dwQueryCond, null, null,true);
                #region  ConditionType
                switch (ConditionType)
                {
                   case "IX_TableList": 
                    DBJobID =  "1023"; 
                    break;
                   case "TX_TableList": 
                    DBJobID =  "1620"; 
                    break;
                   case "IX_TableList_SysID": 
                    DBJobID =  "1897"; 
                    break;
                case "IX_TableList_LikeAny" :
                    DBJobID = "3001";
                 break;
                default:
                 DBJobID = "1001";
                 break;
                }
                dsResult = this.QueryDataBase(dwTableList, DBJobID);
                #endregion
                #region QueryType
                switch (QueryType)
                {
                    case "CreateByQuery":
                        bool Record2Create = false;
                        if (dsResult.Tables[BaseTable].Rows.Count < 1)
                        {
                            Record2Create = true;
                        }
                        if (Record2Create)
                        {
                            DataTable dtTableList = CreateNewTableList(dwTableList);
                            dtTableList.AcceptChanges();
                            dsResult = ImportDataTable(dsResult, dtTableList);
                        }
                        break;
                    case "QueryOnly":
                    default:
                        break;
                }
                #endregion
                foreach (DataTable dtTmp in dsResult.Tables)
                {
                    DsReturn = ImportDataTable(DsReturn, dtTmp);
                }
            }
            catch (Exception ex)
            {
                m_log_out.Error(ex);
            }
            return DsReturn;

        }
        #endregion
        #region CreateNewTableList
        private DataTable CreateNewTableList(DataRow dwTarget)
        {
            //dwTarget=dwTableList;
            DataSet dsTarget = new DataSet();
            DataTable dtTargetTable = dwTarget.Table;
            Queue PrimaryKeyList = new Queue();
            Queue ForeignKeyList = new Queue();
            Queue MPrimaryKeyList = new Queue();
            Queue MForeignKeyList = new Queue();
            try
            {   
                #region QueryCond   
                PrimaryKeyList = new Queue();
                ForeignKeyList = new Queue();
               
                            PrimaryKeyList.Enqueue("SysID");
                            MPrimaryKeyList.Enqueue("SysID");
                            ForeignKeyList.Enqueue("SysID");
                            MForeignKeyList.Enqueue("SysID");
                            PrimaryKeyList.Enqueue("KeyCondition");
                            MPrimaryKeyList.Enqueue("KeyCondition");
                            ForeignKeyList.Enqueue("KeyCondition");
                            MForeignKeyList.Enqueue("KeyCondition");
                            PrimaryKeyList.Enqueue("GoodsKey");
                            MPrimaryKeyList.Enqueue("GoodsKey");
                            ForeignKeyList.Enqueue("GoodsKey");
                            MForeignKeyList.Enqueue("GoodsKey");
                string QueryType = "QueryOnly";
                string MainKeyDefQueryCond = "";
                string TableQueryCond = "SysKeyDataQueryCond"; 
                #endregion
                DataRow dwMainKeyDefQueryCond =
                base.PrepareQueryCond(QueryType, MainKeyDefQueryCond, TableQueryCond, dwTarget, ForeignKeyList, PrimaryKeyList);
                 dsResult = QuerySysKeyData(dwMainKeyDefQueryCond);                 
                dsTarget = base.HandleModelData(dwTarget, dsResult,MForeignKeyList,MPrimaryKeyList);  
           }
            catch (Exception ex)
            {
                m_log_out.Error(ex);
              }
            return dsTarget.Tables[dtTargetTable.TableName];        }
          #endregion
        #endregion
        
 

